<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/layouts/taglib.jsp"%>
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<meta name="renderer" content="webkit|ie-comp|ie-stand">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
<title>数据字典</title>
<style type="text/css">
	.center-font{
		font-size: 38px;
		line-height: 40px;
	}
</style>
</head>
<body>
<nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 首页 <span class="c-gray en">&gt;</span> 系统管理<span class="c-gray en">&gt;</span> 数据字典管理 <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新" ><i class="Hui-iconfont">&#xe68f;</i></a></nav>
<div class="page-container">
	<div class="text-c">
		类型：<input type="text" class="input-text" style="width:250px" placeholder="输入类型(type精确匹配)" id="search_type" name="">
		标签：<input type="text" class="input-text" style="width:250px" placeholder="输入标签(lable精确匹配)" id="search_lable" name="">
		描述：<input type="text" class="input-text" style="width:250px" placeholder="输入名称(模糊匹配)" id="search_description" name="">
		<button type="submit" class="btn btn-success" id="" name=""  onclick="query();"><i class="Hui-iconfont">&#xe665;</i> 搜字典</button>
	</div>
	<div class="cl pd-5 bg-1 bk-gray mt-20"> 
		<span class="l">
			<a href="javascript:;" onclick="datadel()" class="btn btn-danger radius"><i class="Hui-iconfont">&#xe6e2;</i> 批量删除</a> 
			<a href="javascript:;" onclick="pre_add('添加字典','${ctx}/dict/add')" class="btn btn-primary radius"><i class="Hui-iconfont">&#xe600;</i> 添加字典</a>
		</span> 
		<span class="r">共有数据：<strong id="totalCount">88</strong> 条</span> 
	</div>
	<div class="mt-20">
	<table class="table table-border table-bordered table-striped"  id="example">
		<thead>
			<tr class="text-c">
				<th width="25"><input type="checkbox" name="" value=""></th>
				<th width="80">类型</th>
				<th width="100">标签</th>
				<th width="40">键值</th>
				<th width="90">描述</th>
				<th width="90">排序</th>
				<th width="130">创建时间</th>
				<th width="100">操作</th>
			</tr>
		</thead>
		<tbody>
		</tbody>
	</table>
	</div>
</div>
<!--_footer 作为公共模版分离出去-->
<script type="text/javascript" src="${ctxLib }/jquery/1.9.1/jquery.min.js"></script> 
<script type="text/javascript" src="${ctxLib }/layer/2.4/layer.js"></script>
<script type="text/javascript" src="${ctxStatic}/h-ui/js/H-ui.min.js"></script> 
<script type="text/javascript" src="${ctxStatic}/h-ui.admin/js/H-ui.admin.js"></script>
<!--/_footer 作为公共模版分离出去-->

<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript" src="${ctxLib }/datatables/1.10.0/jquery.dataTables.min.js"></script> 
<script type="text/javascript" src="${ctxLib }/laypage/1.2/laypage.js"></script>
<script type="text/javascript" src="${ctxLib }/shopUtil.js"></script>
<script type="text/javascript">
	$(function(){
		query();
	});
	
	/*字典-增加*/
	function pre_add(title,url){
		var index = layer.open({
			type: 2,
			title: title,
			content: url
		});
		layer.full(index);
	}
	
	/*字典-编辑*/
	function pre_edit(title,url,data){
		url = url+"?id="+data;
		pre_add(title,url);
	}
	
	function query(){
		var url = "${ctx}/dict/list";
		$("#example").dataTable({
			"searching" : false,
			"bPaginate" : true,		//开启分页
			"bLengthChange" : 10,	// 每行显示记录数  
	        "iDisplayLength" : 6,		// 每页显示行数
			"bLengthChange":true,//是否显示一个每页长度的选择条
			"aLengthMenu":[[1, 3, 6, -1], [1, 3, 6, "All"]],	//第一个为显示每页条目数的选项，第二个是关于这些选项的解释
			"bAutoWidth": true, 		//是否自适应宽度
			"bProcessing":true,		//是否显示“正在处理”这个提示信息
			"bSort":false,				//是否让各列具有按列排序功能
			"bStateSave":true,			//是否打开客户端状态记录功能
			"bDestroy":true,			//dataTable绑定时，将之前的那个数据对象清除掉，换以新的对象设置
			"serverSide":true,			//开启服务器处理模式
			"sAjaxSource":url,			//请求资源路径
			/*
			 使用ajax，在服务端处理数据
			 sSource:即是"sAjaxSource"
			 aoData:要传递到服务端的参数
			 fnCallback:处理返回数据的回调函数
			 */
			 "fnServerData": function(sSource, aoData, fnCallback){
				 var data = {"aodata" : JSON.stringify(aoData)};
				 var search_type = $("#search_type").val();
				 var search_lable = $("#search_lable").val();
				 var search_description = $('#search_description').val();
				 if(search_type != null && search_type!=""){
					 data.search_type = search_type;
				 }
				 if(search_lable != null && search_lable != ""){
					 data.search_lable = search_lable;
				 }
				 if(search_description != null && search_description != ""){
					 data.search_description = search_description;
				 }
				  $.ajax( { 
					  'type' : 'POST', 
					  "url": sSource, 
					  "dataType": "json", 
					  "data": data,
					  "success": function(resp) { 
						  	$("#totalCount").text(resp.iTotalRecords);
					   		fnCallback(resp);
					   } 
				  }); 
			 }, 
			 "columns": [
					        { "data": "id" },
					        { "data": "type" },
					        { "data": "label" },
					        { "data": "value" },
					        { "data": "description" },
					        { "data": "sort" },
					        { "data": "createDate"},
					        { "data": "id" }
					    ],
		    "columnDefs": [
	                   {
					        targets: 0,
					        render: function(data, type, row, meta) {
					            return '<input type="checkbox" name="checkitem"  id="check'+data+'" value="'+data+'"/>';
					        }
					    },{
					    	targets:3,
					    	render:function(data,type,row,meta){
					    		return data;
					    	}
					    },{
					    	targets: 6,
					    	render:function(data, type, row, meta) {
					    		return new Date(data).Format('yyyy-MM-dd hh:mm:ss');
					    	}
					    },{
					    	targets: 7,
					        render: function(data, type, row, meta) {
					            return '<a title="添加分类" href="javascript:;" onclick="pre_edit(\'添加分类\',\'${ctx}/dict/add\',\''+data+'\');" class="ml-5" style="text-decoration:none">'+
					            '<i class="Hui-iconfont center-font">&#xe600;</i></a>'+
					            '<a title="编辑" href="javascript:;" onclick="pre_edit(\'字典编辑\',\'${ctx}/dict/edit\',\''+data+'\');" class="ml-5" style="text-decoration:none">'+
					            '<i class="Hui-iconfont center-font">&#xe6df;</i></a> <a title="删除" href="javascript:;" onclick="admin_permission_del(this,\''+data+'\')" class="ml-5" style="text-decoration:none"><i class="Hui-iconfont center-font">&#xe6e2;</i></a>';
					        }
					    }],
	     	"rowCallback": function (row, data, displayIndex) {//行定义
	     		 $(row).attr("class", "text-c");
			}
		});
	}
	
	function datadel(){
		var ids = new Array(); 
		$("input[name='checkitem']:checked").each(function(){
			if($(this).val() != null && $(this).val() != ""){
				ids.push($(this).val());
			}
			if(ids.length>0){
				layer.confirm('确认要删除这些字典吗？',function(index){
					$.ajax({
						type: 'POST',
						url: '${ctx}/dict/delete',
						data:{ids:ids},
						dataType: 'json',
						success: function(data){
							if(data.success){
								layer.msg('已删除!',{icon:1,time:1000},function(){
									query();
								});
							}else{
								layer.msg(data.message,{icon:1,time:1000});
							}
						},
						error:function(data) {
							console.log(data.msg);
						},
					});		
				});
			}
		}); 
	}
	</script> 
</body>
</html>